import React,{useState} from 'react';
import useCityReducer from '../../reducers/RDScity';
import {useNavigate} from 'react-router-dom'
const Index = () => {
    const navigate=useNavigate()
    const [state,dispatch] =useCityReducer();
    const [citys] = useState(["上海","武汉","杭州","成都"])
    const handleCity=(val)=>{
        dispatch({
            type:"handleCity",
            value:val
        })
        navigate(-1)
    }
    return (
        <div>
            <p>{state.city}</p>
           {citys.map(item=>{
               return(<button onClick={()=>handleCity(item)} key={item}>{item}</button>)
           })
           }
        </div>
    );
}

export default Index;
